home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Jotto ][ 1.2 / source / Jotto code ƒ / jotto keys.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  4.2 KB  |  193 lines  |  [TEXT/MMCC]

  1. #include "program globals.h"
  2. #include "jotto keys.h"
  3. #include "jotto meat.h"
  4. #include "jotto endgame.h"
  5. #include "jotto dictionary.h"
  6. #include "jotto graphics.h"
  7. #include "jotto environment.h"
  8. #include "sounds.h"
  9. #include "dialogs.h"
  10. #include "error.h"
  11. #include "util.h"
  12. #include "main.h"
  13. #include "graphics.h"
  14.  
  15. #define badWordAlert            202
  16. #define badWordNoCustomAlert    203
  17.  
  18. static pascal Boolean LearnFilter(DialogPtr theDialog, EventRecord *theEvent, short *theItem);
  19.  
  20. void UserHitReturn(WindowPtr theWindow)
  21. {
  22.     short            i;
  23.     
  24.     for (i=0; i<gNumLetters; i++)
  25.         if ((gHumanWord[gNumTries][i]<'A') || (gHumanWord[gNumTries][i]>'Z'))
  26.             return;
  27.  
  28.     if (ValidWord(gHumanWord[gNumTries]))
  29.         UserGuessedValidWord(theWindow);
  30.     else
  31.         UserGuessedInvalidWord(theWindow);
  32. }
  33.  
  34. void UserGuessedValidWord(WindowPtr theWindow)
  35. {
  36.     CalculateNumRight();
  37.     DrawWordInList(theWindow);
  38.     if (gNumRight[gNumTries]==gNumLetters)
  39.         WinGame(theWindow);
  40.     else
  41.     {
  42.         gNumTries++;
  43.         if (gNumTries!=MAX_TRIES)
  44.         {
  45.             DoSound(sound_playword_good, TRUE);
  46.             NewWord();
  47.             SetPort(theWindow);
  48.             DrawCurrentWord(theWindow);
  49.             HighlightChar(theWindow);
  50.         }
  51.         else LoseGame(theWindow);
  52.     }
  53. }
  54.  
  55. void UserGuessedInvalidWord(WindowPtr theWindow)
  56. {
  57.     short        alertResult;
  58.     Str255        tempStr;
  59.     ModalFilterUPP    procFilter = NewModalFilterProc(LearnFilter);
  60.     
  61.     if ((gNumLetters==5) ? (FiveLetterCustomSaveOKQQ()) : (SixLetterCustomSaveOKQQ()))
  62.         DoSound(sound_badword, TRUE);
  63.     Mymemcpy((Ptr)((long)tempStr+1), (Ptr)gHumanWord[gNumTries], gNumLetters);
  64.     tempStr[0]=gNumLetters;
  65.     ParamText(tempStr, "\p", "\p", "\p");
  66.     if ((gNumLetters==5) ? (FiveLetterCustomSaveOKQQ()) : (SixLetterCustomSaveOKQQ()))
  67.     {
  68.         PositionDialog('ALRT', badWordAlert);
  69.         alertResult=NoteAlert(badWordAlert, procFilter);
  70.         DisposeRoutineDescriptor(procFilter);
  71.         if (alertResult==1)
  72.         {
  73.             DoSound(sound_bluffing, TRUE);
  74.             AdmitBluffing(theWindow);
  75.         }
  76.         else
  77.             LearnWord(theWindow);
  78.     }
  79.     else
  80.     {
  81.         DoSound(sound_bluffing, TRUE);
  82.         PositionDialog('ALRT', badWordNoCustomAlert);
  83.         NoteAlert(badWordNoCustomAlert, OneButtonFilter);
  84.         AdmitBluffing(theWindow);
  85.     }
  86. }
  87.  
  88. void AdmitBluffing(WindowPtr theWindow)
  89. {
  90.     if (gNonWordsCount)
  91.         gNumRight[gNumTries]=-1;
  92.     
  93.     UpdateTheWindow(theWindow);
  94.     
  95.     if (gNonWordsCount)
  96.     {
  97.         DrawWordInList(theWindow);
  98.         gNumTries++;
  99.     }
  100.     
  101.     if (gNumTries!=MAX_TRIES)
  102.     {
  103.         NewWord();
  104.         SetPort(theWindow);
  105.         DrawCurrentWord(theWindow);
  106.         HighlightChar(theWindow);
  107.     }
  108.     else
  109.         LoseGame(theWindow);
  110. }
  111.  
  112. void LearnWord(WindowPtr theWindow)
  113. {
  114.     HandleError(SaveCustomWordToDisk(gHumanWord[gNumTries]), FALSE);
  115.     UpdateTheWindow(theWindow);
  116.     UserGuessedValidWord(theWindow);
  117. }
  118.  
  119. void UserHitLeftArrow(WindowPtr theWindow, char charPressed)
  120. {
  121.     HighlightChar(theWindow);
  122.     if (gWhichChar!=0x00)
  123.         gWhichChar--;
  124.     else if (charPressed==0x1c)
  125.         gWhichChar=gNumLetters-1;
  126.     HighlightChar(theWindow);
  127. }
  128.  
  129. void UserHitRightArrow(WindowPtr theWindow)
  130. {
  131.     HighlightChar(theWindow);
  132.     gWhichChar++;
  133.     if (gWhichChar==gNumLetters)
  134.         gWhichChar=0x00;
  135.     HighlightChar(theWindow);
  136. }
  137.  
  138. void UserHitLetter(WindowPtr theWindow, char charPressed)
  139. {
  140.     DoSound(sound_keyclick, TRUE);
  141.     gHumanWord[gNumTries][gWhichChar]=charPressed&0xdf;
  142.     DrawOneChar(theWindow);
  143.     if ((gWhichChar!=gNumLetters-1) || (charPressed==' '))
  144.     {
  145.         gWhichChar++;
  146.         if (gWhichChar==gNumLetters)
  147.             gWhichChar=0x00;
  148.     }
  149.     HighlightChar(theWindow);
  150. }
  151.  
  152. static pascal Boolean LearnFilter(DialogPtr theDialog, EventRecord *theEvent, short *theItem)
  153. {
  154.     unsigned char    theChar;
  155.     
  156.     switch (theEvent->what)    /* examine event record */
  157.     {
  158.         case keyDown:    /* keypress */
  159.         case autoKey:
  160.             theChar=theEvent->message & charCodeMask;    /* get ascii char value */
  161.             if ((theChar==0x0d) || (theChar==0x03))        /* RETURN or ENTER */
  162.             {
  163.                 *theItem=FakeSelect(theDialog, 1);
  164.                 return TRUE;
  165.             }
  166.             if (theEvent->modifiers&cmdKey)
  167.             {
  168.                 switch (theChar)
  169.                 {
  170.                     case 'l':
  171.                     case 'L':
  172.                         *theItem=FakeSelect(theDialog, 2);
  173.                         return TRUE;
  174.                         break;
  175.                     case 'a':
  176.                     case 'A':
  177.                         *theItem=FakeSelect(theDialog, 1);
  178.                         return TRUE;
  179.                         break;
  180.                 }
  181.             }
  182.             break;
  183.         case updateEvt:
  184.             if ((theEvent->message)!=(unsigned long)theDialog)
  185.                 DispatchEvents(*theEvent, FALSE);
  186.             else
  187.                 OutlineDefaultButton(theDialog, 1);
  188.             break;
  189.     }
  190.     
  191.     return FALSE;    /* no faking, proceed as planned */
  192. }
  193.